<?php
namespace Common\Model;

use Think\Model;

class CallModel extends Model
{
    protected $_validate = [
        ['title', 'require', '标题必须填写！'],
        ['content', 'require', '内容必须填写！']

    ];

    //新增记录
    public function addLog()
    {

       if( $this->create()==false){
           $arr['state']='error';
           $arr['info']=$this->getError();
           return $arr;
       }else{
           $present_time=strtotime(date('Y-m-d'));
           $counts=$this->where("sr_time>'%s'",$present_time)->count();
           if($counts > 0){
               $arr['state']='error';
               $arr['info']='你今天已经提交过了';
           }else{
               if($this->add()){
                   $arr['state']='success';
                   $arr['info']='提交成功';
               }else{
                   $arr['state']='error';
                   $arr['info']='提交失败';
               }
           }
           return $arr;

       }
    }
    //拜访记录列表
    public function lister($uid,$page)
    {


           return $this->field("cid,uid,title,content,sr_time")->where("uid=%d and status=%d",[$uid,1])->order("sr_time DESC")->limit("$page,5")->select();

    }
    //带分页记录列表
    public function pageList($uid)
    {

        $counts=$this->where("uid=%d and status=%d",[$uid,1])->count();
        $page=page($counts,10,5);
        $list=$this->where("uid=%d and status=%d",[$uid,1])->limit($page->firstRow, $page->listRows)->select();
        $arr['list']=$list;
        $arr['page']=$page;
        return $arr;
    }
}


















